<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/html/axios.min.js"></script>
    <script src="/html/util.js"></script>
    <script>
        //得到修改学生的ID
        var id = getQuery("id");
        window.onload = function (){
            findClass();
            showStudentInfo();
        }

        /**
         *  显示学生信息
         */
        function showStudentInfo(){
            axios.get("/student/findById",{
                params:{id}
            }).then(e =>{
                var info = e.data;
                $("nameSpan").innerHTML = info.name;
                $("phoneTxt").value = info.phone;
                $("gradeSpan").innerHTML = info.grade;
                $("emailSpan").innerHTML = info.email;
                $("classSelect").value = info.classBean.id;
                $("faceImg").src = "/html/face/"+info.face;
            });
        }

        /**
         * 查询班级信息
         */
        async function findClass(){
            await axios.get("/class/findAll",null).then(e =>{
                var info = e.data;
                var str = "";
                for(var i=0;i<info.length;i++){
                    str += `<option value="${info[i].id}">${info[i].name}</option>`;
                }
                $("classSelect").innerHTML = str;
            });
        }

        function update(){
            axios.get("/student/update",{
                params:{
                    id,
                    phone:$("phoneTxt").value,
                    classId:$("classSelect").value
                }
            }).then(e =>{
               if(e.data == "ok"){
                   location.href="/html/index.html";
               }
            });
        }

    </script>
</head>
<body>
    <h2>修改学生信息</h2>
    <img src="" id="faceImg" width="200" height="200">
    姓名：<span id="nameSpan"></span><br>
    电话：<input type="text" id="phoneTxt"><br>
    email：<span id="emailSpan"></span><br>
    成绩：<span id="gradeSpan"></span><br>
    班级：<select id="classSelect"></select><br>
    <input type="button" value="修改" onclick="update()">

</body>
</html>